﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MemberLayout.master" AutoEventWireup="true"
    CodeBehind="Category.aspx.cs" Inherits="ChatForum.Client.Admin.Category" %>
    
<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" runat="server">
    <div class="actionPanel borderStyle">
        <table>
            <tr>
                <td>
                    <asp:Button ID="Button2" OnClick="OnDeleteCategory" Visible="false" Text="Delete" runat="server" />
                </td>
                <td style="text-align:right">
                    <div>
                        <asp:TextBox ID="searchText" runat="server" />
                        <asp:ImageButton CssClass="centerIcon" ImageUrl="~/images/search.png" Width="20" Height="20" OnClick="OnSearchCategory" CausesValidation="false" AlternateText="Search" runat="server" />
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div id="firstCategoryDiv" runat="server">
        <asp:Button runat="server" Text="Add" OnClick="OnAddFirstCategory" s />
        <asp:TextBox ID="txtName" runat="server" />
        <asp:TextBox ID="txtAge" runat="server" />
        <asp:TextBox ID="txtDescription" runat="server" />
    </div>
    <div>
        <asp:GridView runat="server" ID="categoryListGrid" AutoGenerateColumns="false" GridLines="Horizontal" CssClass="gridRowStyle" HeaderStyle-CssClass="gridHeaderStyle"
            CellPadding="8" ShowFooter="true" ClientIDMode="Predictable" >
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox ID="categorySelector" runat="server" /></ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Title">
                    <ItemTemplate>
                        <asp:TextBox ID="currentTitleId" ReadOnly="true" runat="server" Text='<%#Eval("Name")%>' /></ItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="newName" runat="server" /></FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Minimum Age">
                    <ItemTemplate>
                        <asp:TextBox ID="currentAgeId" runat="server" Text='<%#Eval("AgeRequirement")%>' /></ItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="newAgeRequirement" runat="server" /></FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Description">
                    <ItemTemplate>
                        <asp:TextBox ID="currentDescriptionId" runat="server" Text='<%#Eval("Description")%>' /></ItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="newDescription" runat="server" /></FooterTemplate>
                </asp:TemplateField>
				<asp:TemplateField>
					<ItemTemplate><asp:ImageButton ImageUrl="~/images/modify.png" runat="server" ID="saveCategory" OnClientClick="OnClientSaveCategory(this);" /></ItemTemplate>
					<FooterTemplate><asp:ImageButton ImageUrl="~/images/create.png" runat="server" ID="createCategory" OnClick="OnAddCategory" /></FooterTemplate>
				</asp:TemplateField>
            </Columns>
        </asp:GridView>
		<asp:HiddenField runat="server" ID="currentCategoryTitle" />
		<asp:HiddenField runat="server" ID="currentCategoryAge" />
		<asp:HiddenField runat="server" ID="currentCategoryDescription" />
		<asp:Button ID="updateCategoryButton" runat="server" style="display: none" OnClick="UpdateCategory" />
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="scriptContent" runat="server">	
	<script type="text/javascript">
		function OnClientSaveCategory(saveButton) {

			var currentTitleIdFormat = 'mainContent_mainContent_categoryListGrid_currentTitleId_';
			var currentAgeIdFormat = 'mainContent_mainContent_categoryListGrid_currentAgeId_';
			var currentDescriptionIdFormat = 'mainContent_mainContent_categoryListGrid_currentDescriptionId_';
			var saveButtonIdFormat = 'mainContent_mainContent_categoryListGrid_saveCategory_';

			var currentItemIndex = saveButton.id.replace(saveButtonIdFormat, '');

			document.getElementById('<%=currentCategoryTitle.ClientID %>').value = document.getElementById(currentTitleIdFormat + currentItemIndex).value;
			document.getElementById('<%=currentCategoryAge.ClientID %>').value = document.getElementById(currentAgeIdFormat + currentItemIndex).value;
			document.getElementById('<%=currentCategoryDescription.ClientID %>').value = document.getElementById(currentDescriptionIdFormat + currentItemIndex).value;

			document.getElementById('<%=updateCategoryButton.ClientID %>').click();
		}
	</script>
</asp:Content>
